package com.jueyue.dao.pager.dialect;

import com.jueyue.dao.pager.Pager;

public class OracleDialect implements SqlDialect {

	public String getPagerSql(Pager page, String sql) {
		StringBuffer pagingSelect = new StringBuffer(sql.length() + 100);
		if (page.getPageNumber() > 0) {
			pagingSelect
					.append("select * from ( select row_.*, rownum rownum_ from ( ");
		} else {
			pagingSelect.append("select * from ( ");
		}
		pagingSelect.append(sql);
		if (page.getPageNumber() > 0) {
			pagingSelect.append(" ) row_ ) where rownum_ <= "
					+ page.getPageNumber() * page.getPageSize()
					+ " and rownum_ > " + (page.getPageNumber() - 1)
					* page.getPageSize());
		} else {
			pagingSelect.append(" ) where rownum <= " + page.getPageSize());
		}
		return pagingSelect.toString();
	}
}